package com.tvunetworks.center.user.controller.api;

import com.github.pagehelper.PageInfo;
import com.tvunetworks.center.common.model.vo.PeerIdWithName;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.user.model.param.api.*;
import com.tvunetworks.center.user.model.vo.GridEventVo;
import com.tvunetworks.center.user.service.GridEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @program: tvucc-aggregator
 * @description: GridEventController
 * @author lebronchen
 * @create: 2020-01-06 15:32
 **/
@RestController
@RequestMapping("/openapi/${openApiVersion}/gridEvent")
public class GridEventController {

    @Autowired
    private GridEventService gridEventService;

    @Value("${gridEvent.defaultOrigin}")
    private String defaultOrigin;

    /**
     * 添加预约事件
     * @param param param
     * @return Result
     */
    @PostMapping("/add")
    public Result addEvent(@Valid @RequestBody AddGridEventParam param) {
        param.setOrigin(defaultOrigin);
        return gridEventService.addEvent(param);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/updateEventByTaskID")
    public Result updateEvent(@Valid @RequestBody UpdateGridEventParam param) {
        return gridEventService.updateEvent(param);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/cancelEventByTaskID")
    public Result cancelEvent(@Valid @RequestBody CancelGridEventParam param) {
        return gridEventService.cancelEvent(param);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/delEventByTaskID")
    public Result deleteEvent(@Valid @RequestBody DeleteGridEventParam param) {
        return gridEventService.deleteEvent(param);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/getEventByTaskID")
    public Result getEventByTaskId(@Valid @RequestBody GetGridEventByTaskIdParam param) {
        GridEventVo event = gridEventService.getEventByTaskId(param);
        return ResultUtil.success(event);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/page")
    public Result pageEvent(@Valid @RequestBody GetGridEventParam param) {
        PageInfo<GridEventVo> pageInfo = gridEventService.pageEvent(param);
        return ResultUtil.success(pageInfo);
    }

    /**
     *
     * @param param param
     * @return Result
     */
    @PostMapping("/pageUserReceiver")
    public Result pageUserReceiver(@Valid @RequestBody GetUserReceiverParam param) {
        PageInfo<PeerIdWithName> pageInfo = gridEventService.pageUserReceiver(param);
        return ResultUtil.success(pageInfo);
    }

}
